const nodemailer = require("nodemailer");

let user = 'meibao.huang@argrace.ai',
	pass = 'omjGRznaGfEgVrv9';
let smtpTransport = nodemailer.createTransport({
	host:'smtp.exmail.qq.com',
	port:465,
	//service: 'QQ',
	auth: {
		user: user,
		pass: pass
	}
});

exports.sendMail = async(ctx) => {
	try{
		let reciever_address = ctx.request.body.reciever_address  || [];
		let subject = ctx.request.body.subject || '';
		let html = ctx.request.body.html || '';
		let reciever_address_str = reciever_address.toString();
		console.log(reciever_address_str)
		await new Promise((resolve, reject) => {
			smtpTransport.sendMail({
				from:  user ,
				to: reciever_address_str,
				subject,
				html: `${html} <br> `
			}, function(err, res) {
				if(err === null ) {
					ctx.body = {
						result: 200,
						message: "发送成功"
					};
					resolve(ctx)
				}
			});
		})
	}catch (e) {
		ctx.body = {
			result: 205,
			message: "错误"+e.toString()
		};
	}
}


